package data.structure.binarytree;

/**
 * @ClassName: NodeTree
 * @Description:
 * @Author: qiaopengxiang
 * @Date: 2022/5/8 21:43
 */
public  class NodeTree {

    public int data;

    public NodeTree left;

    public NodeTree right;


    public NodeTree(int data) {
        this.data = data;
    }

    /**
     * 前序遍历  根左右
     * @param root
     */
    public static void preOrder(NodeTree root){
        if (root==null){
            return;
        }
        System.out.println(root.data);
        preOrder(root.left);
        preOrder(root.right);
    }

    /**
     * 中序  左根右
     * @param root
     */
    public static void inOrder(NodeTree root){
        if (root==null){
            return;
        }
        inOrder(root.left);
        System.out.println(root.data);
        inOrder(root.right);
    }

    /**
     * 后序 左右根
     * @param root
     */
    public static void postOrder(NodeTree root){
        if (root==null){
            return;
        }
        preOrder(root.left);
        preOrder(root.right);
        System.out.println(root);
    }
}
